/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.web.core.BaseController;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementCardBo;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementCardSaveBo;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementCardSearchBo;
import com.comac.ins.isfd.domain.bo.IsfdModelManagementCardStructBo;
import com.comac.ins.isfd.domain.vo.IsfdModelManagementCardSearchShowVo;
import com.comac.ins.isfd.domain.vo.IsfdModelManagementCardShowVo;
import com.comac.ins.isfd.domain.vo.IsfdModelManagementCardVo;
import com.comac.ins.isfd.service.IIsfdModelManagementCardService;
import jakarta.validation.constraints.NotEmpty;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 模型管理-单元卡
 *
 * @author hxloongs
 * @date 2024-11-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/modelManagementCard")
public class IsfdModelManagementCardController extends BaseController {

    @Autowired
    private IIsfdModelManagementCardService isfdModelManagementCardService;

    /**
     * 查询单个单元卡
     */
    @SaCheckPermission("isfd:modelManagementCard:query")
    @GetMapping("/detail")
    public R<IsfdModelManagementCardVo> getInfo(@NotEmpty(message = "单元卡主键不能为空") @RequestParam("id") Long id) {
        return R.ok(isfdModelManagementCardService.queryById(id));
    }

    /**
     * 保存并升版
     */
    @SaCheckPermission("isfd:modelManagementCard:save")
    @Log(title = "保存并升版", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PostMapping("/save")
    public R<Void> save(@RequestBody IsfdModelManagementCardSaveBo bo) {
        return toAjax(isfdModelManagementCardService.save(bo));
    }


    /**
     * 单元卡检索定位接口
     */
    @SaCheckPermission("isfd:modelManagementCard:search")
    @PostMapping("/search")
    public R<IsfdModelManagementCardSearchShowVo> search(@RequestBody IsfdModelManagementCardSearchBo bo) {
        return R.ok(isfdModelManagementCardService.search(bo));
    }

    /**
     * 模型管理单元卡结构化
     */
    @SaCheckPermission("isfd:modelManagementCard:struct")
    @Log(title = "模型管理单元卡结构化", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/struct")
    public R<IsfdModelManagementCardShowVo> struct(@Validated(AddGroup.class) @RequestBody IsfdModelManagementCardStructBo bo) {
        return R.ok(isfdModelManagementCardService.structCard(bo));
    }

    /**
     * 模型管理单元卡删除-管理用
     */
    @SaCheckPermission("isfd:modelManagementCard:delete")
    @Log(title = "模型管理零件及卡片删除", businessType = BusinessType.DELETE)
    @RepeatSubmit()
    @PostMapping("/delete")
    public R<Integer> deletePart(@RequestParam Long partId) {
        return R.ok(isfdModelManagementCardService.deletePart(partId));
    }

}
